public class ErFenDemo02 {
    static int[] nums = new int[1000000];

    public static void main(String[] args) {

        for (int i = 0; i < nums.length; i++) {
            nums[i] = i + 1;
        }
        // 二分法
        long s = System.currentTimeMillis();
//        for (int i = 0; i < nums.length; i++) {
//            if (nums[i] == 1000000) {
//                System.out.println("找到了");
//                break;
//            }
//
//        }
//        int index = search(1000000);
//        System.out.println(index);
        System.out.println(System.currentTimeMillis() - s);

//

    }

    public static int search(int num) {

        int min = 0;
        int max = nums.length - 1;
        while (min <= max) {
            int mid = (max + min) / 2;
            if (nums[mid] == num) {
                return mid;
            } else if (num > nums[mid]) {
                min = mid + 1;
            } else if (num < nums[mid]) {
                max = mid - 1;
            }
        }

        return -1;

    }
}
